
package com.hlkj.pay.service.admin.impl;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hlkj.framework.common.pojo.PageResult;
import com.hlkj.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.hlkj.pay.dto.admin.AdminTeamsQueryDto;
import com.hlkj.pay.infrastructure.mapper.admin.AdminTeamsMapper;
import com.hlkj.pay.infrastructure.model.admin.AdminTeamsDO;
import com.hlkj.pay.service.CommonSnFilterService;
import com.hlkj.pay.service.admin.IAdminTeamsService;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author HlpayTeam
 * @date 2024/11/05 14:58
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class AdminTeamsServiceImpl extends CommonSnFilterService implements IAdminTeamsService {

    private final AdminTeamsMapper adminTeamsMapper;

    @Override
    public PageResult<AdminTeamsDO> queryPage(AdminTeamsQueryDto adminTeamsQueryDto) {
        return adminTeamsMapper.selectPage(adminTeamsQueryDto, buildWrapper(adminTeamsQueryDto));
    }

    @Override
    public List<AdminTeamsDO> queryList(AdminTeamsQueryDto adminTeamsQueryDto) {
        return adminTeamsMapper.selectList(buildWrapper(adminTeamsQueryDto));
    }

    @Override
    public AdminTeamsDO queryByName(String name) {
        return adminTeamsMapper.selectOne(AdminTeamsDO::getName, name);
    }

    @Override
    public void addTeams(AdminTeamsDO adminTeamsDO) {
        adminTeamsMapper.insert(adminTeamsDO);
    }

    @Override
    public AdminTeamsDO queryByCode(String code) {
        return adminTeamsMapper.selectOne(AdminTeamsDO::getCode, code);
    }

    @Override
    public void updateTeams(AdminTeamsDO adminTeamsDO) {
        adminTeamsMapper.updateById(adminTeamsDO);
    }

    @Override
    public void deleteTeams(Long id) {
        adminTeamsMapper.deleteById(id);
    }

    /**
     * 查询条件封装
     *
     * @param adminTeamsQueryDto
     * @return
     */
    LambdaQueryWrapper<AdminTeamsDO> buildWrapper(AdminTeamsQueryDto adminTeamsQueryDto) {
        filterSn(adminTeamsQueryDto);
        LambdaQueryWrapperX<AdminTeamsDO> queryWrapper = new LambdaQueryWrapperX<>();
        queryWrapper.eqIfPresent(AdminTeamsDO::getCode, adminTeamsQueryDto.getCode());
        queryWrapper.eqIfPresent(AdminTeamsDO::getName, adminTeamsQueryDto.getName());
        queryWrapper.likeIfPresent(AdminTeamsDO::getCode, adminTeamsQueryDto.getLikeCode());
        queryWrapper.likeIfPresent(AdminTeamsDO::getName, adminTeamsQueryDto.getLikeName());
        queryWrapper.eqIfPresent(AdminTeamsDO::getSn, adminTeamsQueryDto.getSn());
        queryWrapper.inIfPresent(AdminTeamsDO::getSn, adminTeamsQueryDto.getSnList());
        queryWrapper.eqIfPresent(AdminTeamsDO::getSysType, adminTeamsQueryDto.getSysType());
        return queryWrapper;
    }
}
